package com.neutech.variable;

import java.util.Arrays;

/**
 * 数组的赋值和复制
 * @author Neuedu-远哥
 * @version 1.0
 * @date 2021/11/10 16:12
 */
public class Demo13 {
    public static void main(String[] args) {
        // 赋值操作，没有隔离性
        int[] arr1 = {1,2,3,4,5};
        System.out.println(Arrays.toString(arr1));
        int[] arr2 = arr1;
        arr2[2] = 100;
        System.out.println("2:" + Arrays.toString(arr2));
        System.out.println("1:" + Arrays.toString(arr1));
        // 复制操作，有隔离性
        int[] arr3 = new int[arr1.length];
        // JDK提供了一个数组复制的方法
        System.arraycopy(arr1,2,arr3,2,3);
        System.out.println("复制后arr3:" + Arrays.toString(arr3));
        /*arr3[0] = -99;
        System.out.println("3:" + Arrays.toString(arr3));
        System.out.println("1:" + Arrays.toString(arr1));*/
    }
}
